/*
 * Fichier: TestPoint.java
 * Crée le: 19 janvier 2007.
 * Modifié: 12 octobre 2008.
 * Auteurs: Sébastien ESTIENNE.
 * SiteWeb: http://www.prog-info.org/
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package chapitre7.point;



import java.awt.BorderLayout;
import java.text.DecimalFormat;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;



/**
 * <p>Classe permettant de tester la classe Point.</p>
 * @author Sébastien ESTIENNE.
 */
public class TestPoint extends JFrame
{
   /**
    * <p>Serial version UID.</p>
    */
   private static final long serialVersionUID = 1L;


   /**
    * <p>Construction de l'application.</p>
    */
   public TestPoint()
   {
      // Appel du constructeur de la classe JFrame.
      super("Point");

      // Ajoute les composants au conteneur.
      JTextArea zoneSortie = new JTextArea();
      zoneSortie.setEditable(false);
      getContentPane().add(new JScrollPane(zoneSortie), BorderLayout.CENTER);

      // Texte de sortie.
      StringBuilder sortie = new StringBuilder();
      
      // Formateur de nombres.
      DecimalFormat dFormat = new DecimalFormat();
      dFormat.setMinimumIntegerDigits(1);
      dFormat.setMaximumFractionDigits(2);

      // Point 1.
      Point point1 = new Point();
      point1.setX(2.7);
      point1.setY(5.8);
      sortie.append("P1 : ").append(point1).append('\n');

      // Point 2.
      Point point2 = new Point(1.6, 6.3);
      sortie.append("P2 : ").append(point2).append('\n');

      // Point 3.
      Point point3 = new Point(point2);
      point3.setX(4.1);
      sortie.append("P3 : ").append(point3).append('\n');

      // Distance x3.
      double d1 = point3.getDistance(point1);
      sortie.append("Dist(P1-P3) : ").append(dFormat.format(d1)).append('\n');

      double d2 = point3.getDistance(point2.getX(), point2.getY());
      sortie.append("Dist(P2-P3) : ").append(dFormat.format(d2)).append('\n');

      double d3 = Point.getDistance(2.3, 4.2, -6.9, 3.7);
      sortie.append("Dist : ").append(dFormat.format(d3)).append('\n');

      // Déplacer.
      point3.deplacer(-5.1, 4.7);
      sortie.append("Depl(P3) : ").append(point3).append('\n');

      // Translater.
      point3.translater(1.2, -0.7);
      sortie.append("Transl(P3) : ").append(point3).append('\n');

      // Met à jour la zone de sortie.
      zoneSortie.setText(sortie.toString());

      // Modifie les propriétés de la fenêtre.
      setSize(600, 200);
      setLocation(100, 100);
      setVisible(true);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }


   /**
    * <p>Débute l'exécution du test.</p>
    * @param args Les paramètres de la ligne de commande.
    */
   public static void main(String[] args)
   {
      new TestPoint();
   }
}
